package com.bk.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;

import booking.utils.TimeUtils;

public class BKBookingUtils extends TimeUtils {
	public BKBookingUtils() {
		super(2);
	}
	
	
	public ArrayList<String> selectionDates() {
		ArrayList<String> dates = new ArrayList<String>();
		for (int i = 0; i < 15; i++) {
			Calendar cal = Calendar.getInstance();
			cal.add(Calendar.DATE, i);
			String day = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
			dates.add(day);
		}
		return dates;
	}

	public ArrayList<Boolean> businessHours(int open, int close, ArrayList<Boolean> array) {

		for (int i = 0; i < open * timeScale; i++) {
			array.set(i, false);
		}

		for (int i = close * timeScale; i < 24 * timeScale; i++) {
			array.set(i, false);
		}

		return array;
	}

	private ArrayList<Boolean> getSpareTime() {
		ArrayList<Boolean> array = new ArrayList<Boolean>();
		for (int i = 0; i < timePiece; i++) {
			array.add(true);
		}

		array = businessHours(10, 22, array);
		return array;
	}

	public ArrayList<HashMap<String, Object>> timeArray() {

		ArrayList<Boolean> spareTimeArray = getSpareTime();
		int i = 0;
		int time = -1;
		String string = "";
		ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String, Object>>();
		for (Boolean boolean1 : spareTimeArray) {
			if (time == -1) {
				if (boolean1) {
					time = i;
				}
			}
			int hour = i / timeScale;
			int minute = i % timeScale * (60 / timeScale);
			String timeFmt = hour + ":" + ((minute == 0) ? "00" : minute);
			string = string + timeFmt + "\t: " + boolean1 + "\n";
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("time", timeFmt);
			map.put("flag", boolean1);
			map.put("selected", i == time);
			map.put("index", i);
			arrayList.add(map);
			i++;
		}
		return arrayList;
	}
}
